﻿// -----------------------------------------------------------------------
// Copyright (c) David Kean. All rights reserved.
// -----------------------------------------------------------------------
extern alias pcl;
using System.Security.Cryptography;
using System.Security.Cryptography.Adaptation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Portable.Security.Cryptography.Adaptation
{
    [TestClass]
    public class CryptographyFactoryTests
    {
        [TestMethod]
        public void CreateAesManaged_ReturnsSymmetricAlgorithmAdapterWrappingAesManaged()
        {
            var factory = new CryptographyFactory();

            var result = (SymmetricAlgorithmAdapter)factory.CreateAesManaged();

            Assert.IsInstanceOfType(result.UnderlyingAlgorithm, typeof(AesManaged));
        }

        [TestMethod]
        public void CreateHMacSha1_ReturnsKeyedHashAlgorithmAdapterWrappingHMACSHA1()
        {
            var factory = new CryptographyFactory();

            var result = (KeyedHashAlgorithmAdapter)factory.CreateHMacSha1();

            Assert.IsInstanceOfType(result.UnderlyingAlgorithm, typeof(HMACSHA1));
        }

        [TestMethod]
        public void CreateHMacSha256_ReturnsKeyedHashAlgorithmAdapterWrappingHMACSHA256()
        {
            var factory = new CryptographyFactory();

            var result = (KeyedHashAlgorithmAdapter)factory.CreateHMacSha256();

            Assert.IsInstanceOfType(result.UnderlyingAlgorithm, typeof(HMACSHA256));
        }

        [TestMethod]
        public void CreateSha1Managed_ReturnsHashAlgorithmAdapterWrappingSHA1Managed()
        {
            var factory = new CryptographyFactory();

            var result = (HashAlgorithmAdapter)factory.CreateSha1Managed();

            Assert.IsInstanceOfType(result.UnderlyingAlgorithm, typeof(SHA1Managed));
        }

        [TestMethod]
        public void CreateSha256Managed_ReturnsHashAlgorithmAdapterWrappingSHA256Managed()
        {
            var factory = new CryptographyFactory();

            var result = (HashAlgorithmAdapter)factory.CreateSha256Managed();

            Assert.IsInstanceOfType(result.UnderlyingAlgorithm, typeof(SHA256Managed));
        }
    }
}
